<?
define('PC', 1);
include("ggheader_new_gly.php");
include_once("/var/www/html/new/com.inc.php");
include_once('/var/www/html/wx/api/v0.0.1/init.php');
include_once("/var/www/html/new/d/class/Member.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$m = new Member($s,APPLY_DID);
$lid = $_REQUEST['lid'];
$sql = "SELECT id,title,address,area,jtype,p_type,imgpath,px,jqts,bhjq,jtzn FROM uu_land WHERE id=$lid LIMIT 1";
$GLOBALS['le']->query($sql);
$data = $GLOBALS['le']->fetch_assoc();
$salePros   = salePros($_SESSION['domain_mid'],$lid);
function salePros($apply_did,$lid=Null){

	$account = ($_SESSION['saccount']) ? $_SESSION['saccount']:$_SESSION['account'];
	$r=array();
	$salePids=array();
	$str="select tid,aid,dprice from uu_priceset where pid={$apply_did}";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$dprices[$row['tid']."_".$row['aid']]=$row['dprice'];
	}
	$sql=<<<SQL
select p.id as pid,p.apply_did,p.p_status,l.id as lid,l.p_type,l.areacode,
l.title,getPY(l.title,1) as py,l.area,l.topic,l.px,l.runtime,l.taobao_support,l.imgpath,
l.address,t.id as tid,t.pay,t.getaddr,t.title as ttitle,t.tprice,t.notes,
t.buy_limit_low,t.ddays,t.delaydays,t.status,f.ass_station,
f.mdays,f.mhour,f.rdays,t.order_end,t.delaytype,t.sync_status
from uu_products p left join uu_land l on p.contact_id=l.id left join
uu_jq_ticket t on p.id=t.pid left join uu_land_f f on f.pid=p.id
SQL;
	$where= ($lid==5322 || $lid==5154) ? "where p.p_status=0 and p.apply_limit=1":"where p.p_status=0 and p.apply_limit=2";
	if($lid) $where.=" and l.id=$lid ";
	$orderby=" order by l.px desc ";
	/*一手供应商产品*/
	$aids=array(0=>$apply_did);
	$str="SELECT l.pids,l.aid FROM pft_product_sale_list l LEFT JOIN pft_member m ON l.aid=m.id WHERE l.fid={$apply_did} AND l.status=0 AND m.status=0";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$salePids[$row['aid']]=explode(",",$row['pids']);
		$aids[]=$row['aid'];
	}
	if(count($aids)!=0){
		$aids=implode(",",$aids);
		$where1=$where." AND p.apply_did in ($aids) ";
		$str1="$sql $where1 $orderby";
		$GLOBALS['le']->query($str1);
		while($row=$GLOBALS['le']->fetch_assoc()){
			if($row['apply_did']!=$apply_did
				&&$salePids[$row['apply_did']][0]!="A"
				&&!in_array($row['pid'],$salePids[$row['apply_did']]))
			{
				continue;
			}
			$row['sapply_did']=$row['apply_did'];
			$row['aid']=0;
			$row['lvl']=0;
			$r[]=$row;
		}
	}
	/*二手供应商产品*/
	$str="select pid,sid from pft_p_apply_evolute where fid={$apply_did} and status=0 and sid<>sourceid";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$secondInfo[$row['pid']."_".$row['sid']]=$row;
		$secondPids[]=$row['pid'];
	}
	if(count($secondPids)!=0){
		$proInfo    = array();
		$secondPids = implode(",",$secondPids);
		$where2     = $where." and p.id in ($secondPids) ";
		$str2       = "$sql $where2 $orderby";
		$GLOBALS['le']->query($str2);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$proInfo[$row['pid']]=$row;
		}
		foreach($secondInfo as $key=>$value){
			list($pid, $sapply_did) = explode("_",$key);
			if(!$proInfo[$pid]) continue;
			$row    = $proInfo[$pid];
			$row['sapply_did']=$sapply_did;
			$row['aid']=$sapply_did;
			$row['lvl']=$value['lvl'];
			$row['eid']=$value['id'];
			$row['estatus']=$value['status'];
			$aids   = explode(",",$value['aids']);
			$aids[] = $value['fid'];
			$aids[0]=0;
			$r[]=$row;
		}
	}
	return $r;
}
$tickets = array();
$date = date('Y-m-d');
$land = array();
foreach($salePros as $k=>$ticket){ // 处理价格
    $xml = $s->Dynamic_Price_And_Storage('',$ticket['pid'],$date,1,1,1);
    if($xml==105 || $xml==1065) continue;// 没有价格表示没有出售
    $object = simplexml_load_string($xml);
    $uprice= (string)$object->Rec->UUsprice;
    $ticket['uprice'] = $uprice/100;
    $ticket['storage'] = (string)$object->Rec->UUstorage;
    // 景区信息
    if(!$land['ltitle']){
        $land['p_type'] = $ticket['p_type'];
        $land['ltitle'] = $ticket['title'];
        $land['imgpath'] = 'http://www.12301.cc/'.$ticket['imgpath'];
    }
    $land['tickets'][] = $ticket;
}

define('DETAIL_LINK','/new/d/shops/gdetail.html');// 详情链接地址
$hot = $saveArr['products']['A'];
shuffle($hot);

//处理下产品简介
$z = htmlspecialchars_decode($data['bhjq']);
$z = strip_tags($z);
$z1 = mb_substr($z,0,43,'utf-8').'...';
?>
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/shops/css/gdetail.css"/>
<div class="ggMainCon ggw1100 clearfix">
    <div class="mainCol ggw1100">
        <div id="buyWrap" class="buyWrap clearfix">
            <div class="photoW col l ggshadow"><table class="photoTable"><tr><td><img src="<?=$land['imgpath']?>" alt=""/></td></tr></table></div>
            <div class="col pdetail r">
                <div class="tit line ggellipsis"><?=$land['ltitle']?></div>
                <div class="desc line"><?
                if($_REQUEST['lid']==5322)
                {echo $z1;}
                else
                {echo $z;}?></div>
                
                <?/*志萍测试购买菽庄花园 之后记得关闭*/?>
                <?if($_REQUEST['lid']==5322 || ($_SESSION['account']==15959110791 && $_REQUEST['lid']==5154)):?>
                <div class="price line clearfix">
                    <div class="l col">价格：</div>
                    <div class="r col"><i class="yen">&yen;</i><span id="nprice" class="num"><?=$land['tickets'][0]['uprice']?></span><span id="opricew" class="oldp">原价<span id="nprice">199</span></span></div>
                </div>
                <div class="tclass line clearfix">
                    <div class="l col">选择票类：</div>
                    <div class="r col" id="ticketList">
                        <?foreach($land['tickets'] as $k=>$ticket):?>
                        <span class="tbox<?if($k==0) echo ' active';?>" data-nprice="<?=$ticket['uprice']?>" data-storage="<?=$ticket['storage']?>" data-lid=<?=$lid?> data-tid="<?=$ticket['tid']?>" data-pid="<?=$ticket['pid']?>" data-type="<?=$ticket['p_type']?>" data-aid="<?=$ticket['sapply_did']?>"><?=$ticket['ttitle']?></span>
                        <?endforeach;?>
                    </div>
                </div>
                <div class="date line clearfix">
                    <div class="l col">游玩日期：</div>
                    <div class="r col"><input type="text" class="dateInp" id="dateInp" value="2014-12-20"/><i class="gsprite gicon calder"></i></div>
                </div>
                <div class="count line clearfix">
                    <div class="l col">预订数量：</div>
                    <div class="r col">
                        <div class="countGroup clearfix">
                            <a class="btn minu gsprite gicon minuCount" id="minuCountBtn" href="#"></a>
                            <input class="countInp" id="countInp" type="text" value="1"/>
                            <a class="btn plus gsprite gicon addCount" id="addCountBtn" href="#"></a>
                        </div>
                        <div id="storagew" class="storage">库存：<span id="storageCount" class="storageCount">100</span></div>
                    </div>
                </div>
                <div class="line clearfix btn">
                    <input class="submitBtn buy" id="buyBtn" type="button" value="预订"/>
                   <!--  <input class="submitBtn addCart" id="addCartBtn" type="button" value="加入购物车"/> -->

                </div>
                <?endif;?>
            </div>
        </div>
        <div id="detailWrap" class="detailWrap">
            <ul class="tabHead clearfix">
                <li class="tabLi yunding active">预订须知</li>
                <li class="tabLi jianjie">景点简介</li>
                <li class="tabLi jianjie">交通指南</li>
            </ul>
            <div class="detailCon yunding">
                <?=nl2br($data['jqts']);?>
            </div>
            <div class="detailCon jianjie">
                <?=htmlspecialchars_decode($data['bhjq']);?>
            </div>
            <div class="detailCon zhinan">
                <?=nl2br($data['jtzn'])?>
            </div>
        </div>
    </div>
</div>
<?php include("ggfoot.php");?>
    <span id="movetocartIcon" class="movetocartIcon"></span>
<script type="text/javascript" src="http://www.12301.cc/shops/js/gdetail_new_gly.js"></script>
<script>
//$('.desc').css('height',250);
//$('.pdetail').css({'width':500;'margin-left':80px});
//$('.ggellipsis').css('text-align','center');
</script>
</body>